Investigate: Strong typing across microfrontends #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
One of the disadvantages of using Microfrontends is developers lose type information because components are loaded at runtime, rather than at compile time.
E.g.
A team running Microfrontend A relies on a component in Microfrontend B which takes
{ a: number }
as props. If for some reason, the props become{ a: string }
this can have consequences on the operation of Microfrontend A, if this change is not properly handled in B's instantiation logic.What Ifs?
How this PR helps?
In this PR:
microfrontend-manifest.json
file:jsonSchemaOf
function that returns JSON schema of a zod typeregister
function to provide strict typing of exposed modulesregister
function run in a non-browser environment, so return metadata of exposed modules.mf-*/package.json
can have an equivalent git-ignoredpackage.json.d.ts
file that provides intellisense, so we can use the package's name as the scope of the microfrontend with strict typing.microfrontend-manifest.json
file is used to provide type checks in the IDE.